<%@page import="systems.ConfigSystem"%>
<%@page import="entities.SiteConfig"%>
<%@page import="systems.AdsSystem"%>
<%@page import="entities.MetaSeo"%>
<%@page import="helpers.StringHelper"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="entities.Category"%>
<%@page import="java.util.Map"%>
<%@page import="entities.Answer"%>
<%@page import="entities.Question"%>
<%@page import="java.util.List"%>
<%@page import="entities.AuthorQuestion"%>
<%@page import="entities.Author"%>
<%
SiteConfig siteConfig = ConfigSystem.getConfigs();
Author author = (Author) request.getAttribute("author");
AuthorQuestion authorQuestion = (AuthorQuestion) request.getAttribute("authorQuestion");
Author a = null;
Category c = null;

List<Question> questions = (List<Question>) request.getAttribute("questions");
List<Question> answers = (List<Question>) request.getAttribute("answers");
Map<String, Author> qAuthors = (Map<String, Author>) request.getAttribute("qAuthors");
Map<String, Author> aAuthors = (Map<String, Author>) request.getAttribute("aAuthors");
Map<String, Category> qCategories = (Map<String, Category>) request.getAttribute("qCategories");
Map<String, Category> aCategories = (Map<String, Category>) request.getAttribute("aCategories");
MetaSeo metaseo = (MetaSeo) request.getAttribute("metaseo");

//Set content for Seo
Map<String, String> replates = new TreeMap<String, String>();
replates.put("__SERVER_NAME__", UrlHelper.getDomainServer(request));
replates.put("__SERVER_URL__", UrlHelper.getServerUrl(request));
replates.put("__AUTHOR_NAME__", author.getName());
replates.put("__AUTHOR_ALIAS__", author.getAlias());
replates.put("__AUTHOR_ID__", author.getId());


String title = StringHelper.replateContent(metaseo.getTitle(), replates);
String description = StringHelper.replateContent(metaseo.getDescription(), replates);
String keywords = StringHelper.replateContent(metaseo.getKeywords(), replates);
String url = StringHelper.replateContent(metaseo.getOgurl(), replates);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/templates/default_lang/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=url %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>

		<script type="text/javascript" src="/templates/<%=siteConfig.getTemplate() %>/js/author.js"></script>
		
		<div class="mainContent clearafter">
			<div class="leftMainContent">
				<!-- Content Tab -->
				<div class="content">
					<div class="content_in">
						<!-- user profile -->
						<div class="user_profile">
							<div class="author_photo">
								<img src="<%=author.getAvatar() %>" class="agent_photo" width="150" height="150" >
							</div>
							<div class="agent_biodata">
								<h3><%=author.getName() %></h3>
								<p class="listlinks">
									<span class="i_agent_others">
										<a href="#questions">Questions Asked : <b><%=authorQuestion != null ? authorQuestion.getqIds().size() : "0" %></b></a>
									</span>
									<span class="answers_provider">
										<a href="#answers">Answers provided : <b><%=authorQuestion != null ? authorQuestion.getaIds().size() : "0" %></b></a>
									</span>
								</p>
								
								<div class="adv">
									<%=AdsSystem.getAds234x60() %>
								</div>
							</div>
						</div>
						<!-- end user profile -->
						
						<br /><br />
						
						<!-- tabs question -->
						<ul class="user_tabs">
							<li class="active"><a href="#questions">Questions Asked</a></li>
							<li><a href="#answers">Answers Provided</a></li>
						</ul>
						<!-- end tabs question -->
						
						
						<div id="tabs-content">
							<div id="questions">
								<%
								for (Question question : questions) {
									a = qAuthors.get(question.getAuthor());
									c = qCategories.get(question.getCategory());
								%>
								<!-- question_item -->
								<div class="question_item clearafter">
									<span class="total_answers">
										<a href="/question/<%=question.getId() %>"><%=question.getAnswers().size() %></a> Answers
									</span>
									<h3>
										<a href="/question/<%=question.getId() %>" title="<%=question.getTitle()%>"><%=question.getTitle() %></a>	
									</h3>
									<p>
										<% if (a != null) { %>
										<span class="user">
											Asked by: 
											<strong>
												<a href="/author/<%=a.getAlias() %>-<%=a.getId() %>" title="<%=a.getName()%>"><%=a.getName()%></a>
											</strong>
											
										</span>
										<% } %>
										<% if (c != null) { %>
										<span class="pcate">
											<a rel="tag" href="/category/<%=c.getAlias() %>-<%=c.getId()%>"><%=c.getName() %></a><br>
										</span>
										<% } %>
									</p>
								</div>
								<!-- end question_item -->
								<% } %>
							</div>
							
							<div id="answers">
								<%
								for (Question question : answers) {
								%>
								<!-- question_item -->
								<div class="question_item clearafter">
									<span class="total_answers">
										<a href="/question/<%=question.getId() %>"><%=question.getAnswers().size() %></a> Answers
									</span>
									<h3>
										<a href="/question/<%=question.getId() %>" title="<%=question.getTitle()%>"><%=question.getTitle() %></a>	
									</h3>
								</div>
								<!-- end question_item -->
								<% } %>
							</div>
						</div>
					</div>
				</div>
				<!-- End Content tab -->
			</div>
			<jsp:include page="/templates/default_lang/elements/right.jsp" />
		</div>
<jsp:include page="/templates/default_lang/layouts/footer.jsp" />